-- local BasePart = require("packages.mvc.BasePart")
local CURRENT_MODULE_NAME = ...
local CreateRoomPart = class("CreateRoomPart", PokerPartBase) --登录模块
local CreateRoomLogic = require(GamePath .. ".components.lobby.createroom.createroomlogic")
CreateRoomPart.DEFAULT_PART = {}
CreateRoomPart.DEFAULT_VIEW = "createroomlayer"
 
--类型配置
local typeConfig = {
	[1] = {name = "jushuType", title = "局数选择：",itemType = "RadioGroup",desc= {"6局","12局","18局"},value={1,2,3},defaultIndx = 1,
	lines=1,template = "template1"},
	[2] = {name = "payType",title = "支付选择：",itemType = "RadioGroup",desc= {"房主支付","AA支付"},value={0,1},defaultIndx = 1,
	lines=1,template = "template1"},
	[3] = {name = "landType",title = "确定地主：",itemType = "RadioGroup",desc= {"抢地主","叫分"},value={1,2},defaultIndx = 1,
	lines=1,template = "template1"},
	[4] = {name = "landTopType",title = "地主封顶：",itemType = "RadioGroup",desc= {"32分","64分","128分","无上限"},value={1,2,3,4},defaultIndx = 1,
	lines=1,template = "template1"},
	[5] = {name = "timeOverOprt",title = "超时托管：",itemType = "CheckBox",desc= {"超时托管",},value={1,},defaultIndx = 1,
	lines=1,template = "template1"},
	[6] = {name = "tips",title = "开%d局房主需要支付%s钻石",itemType = "Text",desc= {},value={},defaultIndx = 1,
	lines=1,template = "template1"}
}


--超时托管

--[
-- @brief 构造函数
--]
function CreateRoomPart:ctor(owner)
    CreateRoomPart.super.ctor(self, owner)
    self:initialize()

end

--[
-- @override
--]
function CreateRoomPart:initialize()
	cc.bind(self, "loadinglogic");
	cc.bind(self, "roomlogic");
end

--激活模块
function CreateRoomPart:activate(data)
	CreateRoomPart.super.activate(self,CURRENT_MODULE_NAME)

	local dataConfig = {
		[1] = {
			typeConfig[1];
			typeConfig[2];
			typeConfig[3];
			typeConfig[4];
			typeConfig[5];
			typeConfig[6];
		},
	}
	--每次重新创建
	self.createRoomLogic = CreateRoomLogic.new(self); --创建房间logic
    self.createRoomLogic:addAllCheckBoxClickListener(self.onCheckBoxClick); --注册监听
	self.createRoomLogic:updateCreateRoomNode(1, self.view.node.listViewLayout, dataConfig[1]);
end

function CreateRoomPart:deactivate()
	self.createRoomLogic = nil ;
	CreateRoomPart.super.deactivate(self,CURRENT_MODULE_NAME)
end

function CreateRoomPart:getPartId()
	-- body
	return "CreateRoomPart"
end

function CreateRoomPart:createGame()
	self:requestCreateRoom();
	self:startLoading()
end

function CreateRoomPart:requestCreateRoom( gameId )
	local user = global:getGameUser();
	local game_player = user:getProp("gameplayer");
	local reqEnterRoomData = ddzCommon_pb.CreateVipRoomMsg();
	local serverdata = self.createRoomLogic:getServerData();

	reqEnterRoomData.quanNum = serverdata.jushuType * 6;
	reqEnterRoomData.roomid = 2002;
	reqEnterRoomData.payType = serverdata.payType;
	reqEnterRoomData.selectWayNum = serverdata.landType;
    --[[
    新增字段赋值
    self.cur_lord_type   1,2
	self.cur_limits_type  1,2,3,4
	self._isAutoOutcard = true   true or false
    ]]
    local extendInfo = ddz_pb.DDZCreatTableExtend();
    extendInfo.jushuType = serverdata.jushuType;		-- 局数选择
    extendInfo.landType = serverdata.landType;		-- 玩法，叫抢 or 叫分
    extendInfo.landTopType = serverdata.landTopType;		-- 地主分数封顶
    extendInfo.timeOverOprt = serverdata.timeOverOprt and 1 or 0;	-- 是否超时托管

    reqEnterRoomData.extendInfo = extendInfo:SerializeToString();
	
	Log.d("CreateRoomPart:createGame reqEnterRoomData: ", reqEnterRoomData.quanNum);
	global:getNetManager():sendProtoMsg(reqEnterRoomData, DdzSocketConfig.REQ_CREATE_TABLE, DdzGameConfig.GAME_ID);
end


function CreateRoomPart:onCheckBoxClick(currentData,listview,serverdata,currentIndex)
	local desctxt = nil
	Log.d("serverdata->",serverdata);
	local selectTimes = serverdata.jushuType ;
	if serverdata.payType == 0 then
		desctxt = string.format(DdzString.createroomdiamondtext1, selectTimes * 6, selectTimes * 3);
	else
		desctxt = string.format(DdzString.createroomdiamondtext2, selectTimes * 6, selectTimes);
	end
	--设置消耗砖石显示
	local tipsView = listview:getChildByName("tips");
    if tipsView then
    	tipsView:getChildByName("title"):setString(desctxt);
    end
    listview:setScrollBarEnabled(false);
end

function CreateRoomPart:_onEnterRoomAck(  )
	self:stopLoading();
end

CreateRoomPart.eventFuncMap = {
    [SocketConfig.MSG_REQUEST_START_GAME_ACK] 		= CreateRoomPart._onEnterRoomAck;
};

return CreateRoomPart 